package com.eco.util;

import cn.hutool.captcha.LineCaptcha;
import com.eco.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Random;
import java.util.UUID;

@Component
public class CaptchUtil {
    private  LineCaptcha lineCaptcha = cn.hutool.captcha.CaptchaUtil.createLineCaptcha(200,100);

    @Autowired
    RedisService redisService;

    public String[] getImge() {
       lineCaptcha.createCode();
        String code = lineCaptcha.getCode();
        String key = UUID.randomUUID().toString();
        //存储验证码
        redisService.setex(key,300,code);

        String imgBase = lineCaptcha.getImageBase64();
        String[] result = {key,imgBase};
        return result;
    }
//    public static void main (String[] args) {
//        System.out.println(lineCaptcha.getImageBase64());
//    }
}
